<template>
  <div>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多数据"
      @load="onLoad"
      :immediate-check="false"
      :error="error"
    >
      <!-- 退款 -->
      <div
        class="flex-column"
        style="background-color:#fff;margin-top:10px;"
        v-for="(item,index) in list"
        :key="index"
        @click="orderDetail(item)"
      >
        <div class="row-space-between">
          <p class="p-orderid">订单号：{{item.orderID}}</p>
          <p style="font-size: 13px;margin-right:14px;" v-if="item.stateID ==5">申请退款中</p>
          <p style="font-size: 13px;margin-right:14px;" v-if="item.stateID ==6">已退款</p>
          <p style="font-size: 13px;margin-right:14px;" v-if="item.stateID ==7">商家已取消</p>
        </div>
        <div class="column-center">
          <div class="list-item flex-row">
            <van-image width="116" height="116" fit="contain" :src="item.courseImg"></van-image>
            <div class="column-space-between course-detail">
              <div>
                <p class="text-p2">{{item.courseName}}</p>
                <p class="text-p3">
                  {{item.courseType}}-
                  <van-icon name="location" size="10" color="#F40404" />
                  {{item.courseAddress}}
                </p>
              </div>
              <div>
                <p class="text-p3">已选：{{item.specification}}</p>
                <div class="row-space-between" style="text-align:left">
                  <span style="color:#F40404;">￥{{item.originalPrice|fixed}}</span>
                  <span style="color: rgba(16, 16, 16, 0.65);font-size: 10px;">x1</span>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="flex-row count">
          合计：
          <span style="color:#F40404;" v-if="item.realAmount !=0">￥{{item.realAmount|fixed}}</span>
          <span style="color:#F40404;" v-if="item.preAmount!=0">￥{{item.preAmount|fixed}}</span>
        </div>
      </div>
    </van-list>
  </div>
</template>

<script>
import { GetOrder } from "@/api/personal";
import { mapGetters } from "vuex";
import { Toast } from "vant";
export default {
  data() {
    return {
      list: [],
      page: 1, //当前页码
      pageSize: 5, //一页显示的总数
      total: 0,
      lastPage: 0,
      loading: false,
      finished: false,
      error: false
    };
  },
  methods: {
    async onLoad() {
      if (this.lastPage != 0 && this.page < this.lastPage) {
        this.page += 1;
        const result = await GetOrder({
          page: this.page,
          size: this.pageSize,
          customerAccount: this.phone,
          showState: "4"
        });
        if (result.result == "OK") {
          this.list = this.list.concat(result.data.data);
        } else {
          this.error = true;
        }
      }
      this.loading = false;
      if (this.lastPage == this.page) {
        this.finished = true;
      }
    },
    // 订单详情
    orderDetail(value) {
      this.$router.push({
        name: "OrderDetail"
      });
      this.$store.commit("setSubmitOrderId", value.orderID);
    }
  },
  async created() {
    Toast.loading({
      message: "加载中...",
      forbidClick: true
    });
    const result = await GetOrder({
      customerAccount: this.phone,
      showState: "4",
      size: this.pageSize,
      page: this.page
    });
    console.log("订单：", result);
    if (result.result == "OK") {
      this.list = result.data.data;
      this.total = result.data.total;
      this.lastPage = result.data.lastpage;
    }
    if (result.msg == "暂无订单信息") {
      this.finished = true;
    } else {
      this.finished = false;
    }
    Toast.clear();
  },
  computed: {
    ...mapGetters({ phone: "getPhone" })
  },
  filters: {
    fixed(value) {
      return parseFloat(value).toFixed(2);
    }
  }
};
</script>


<style scoped>
.text-p2 {
  color: rgba(16, 16, 16, 1);
  font-size: 14px;
  text-align: left;
  margin: 3px 0 3px 0;
}
.text-p3 {
  margin: 0;
  color: rgba(16, 16, 16, 0.65);
  font-size: 10px;
  text-align: left;
  line-height: 12px;
}
.list-item {
  width: 95%;
  height: 116px;
  background-color: #fff;
  line-height: 20px;
  border-radius: 4px;
  color: rgba(16, 16, 16, 1);
  font-size: 14px;
  font-family: Arial;
  border: 1px solid rgba(255, 255, 255, 0);
}
.p-orderid {
  color: rgba(58, 58, 58, 0.65);
  font-size: 12px;
  text-align: left;
  margin-left: 14px;
}
.count {
  justify-content: flex-end;
  margin: 5px 18px 5px 0;
  font-size: 12px;
}
.course-detail {
  background-color: #fafafa;
  padding: 7px;
  width: 241px;
}
</style>